package cn.jdx.tools.md4img.tools;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class JdxToolsReadFileToList {
    public static List<String> getContentList(String filePath) {
        //[1].创建实例
        List<String> contentList = new ArrayList<>();
        BufferedReader bufferedReader = null;
        try {
            bufferedReader = new BufferedReader(new FileReader(filePath));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        //[2].开始读取
        String line = "";
        try {
            while((line = bufferedReader.readLine())!= null){
                contentList.add(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                if (bufferedReader!=null){
                    bufferedReader.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        //[3].返回内容
        return contentList;
    }

}
